package x.y.z;

public class LeetCode_0605 {
    public static boolean canPlaceFlowers(int[] flowerbed, int n) {
        int count = 0;
        for (int i = 0; i < flowerbed.length; i++) {
            if (flowerbed[i] == 1) {
                continue;
            }
            boolean left = true;
            if (i - 1 >= 0) {
                if (flowerbed[i - 1] == 1) {
                    left = false;
                }
            }
            boolean right = true;
            if (i + 1 < flowerbed.length) {
                if (flowerbed[i + 1] == 1) {
                    right = false;
                }
            }
            if (left && right) {
                count++;
                flowerbed[i] = 1;
            }
        }
        return count >= n;
    }
}
